#include "common.h"
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(){
  //1.先生产独有的key用来做共享内存的标识
  key_t key = ftok(pathname,proj_id);
  //2.向系统生产一块共享内存
  int shm_id = shmget(key,4096,IPC_CREAT|0644); //可以跟上对这块内存的使用权限
  //3.将该内存映射到进程的地址空间上
  char* buf = (char*)shmat(shm_id,NULL,0);
  //4.向该内存中写入数据
  char* str = "client send the message to shmmemory!";
  int count = 0;
  while(count<5){
    strcpy(buf+(count*(strlen(str)+1)),str);
    printf("client write:%s\n",buf+((strlen(str)+1)*count));
    ++count;
    sleep(1);
  }
  //5.解绑该内存与进程的映射关系
  shmdt(buf);
  printf("client write done!\n");
  return 0;
}
